package com.witdata.quartz.config;

import com.witdata.quartz.job.InstanceHeartbeatJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfiguration {

    @Bean
    public JobDetail jobDetail() {

        return JobBuilder.newJob(InstanceHeartbeatJob.class)
                .withIdentity("instanceHeartbeatJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger trigger(JobDetail jobDetail) {
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(30)
                .repeatForever();
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail)
                .withIdentity("instanceHeartbeatTrigger")
                .withSchedule(simpleScheduleBuilder)
                .build();
    }


}
